<?php

error_reporting(0);
$link = $_GET['link'];
$rlink = $link;
require_once("config.php");
function get_link($link)
{

$ch = curl_init($link);

$cookie = array();
    foreach( $_COOKIE as $key => $value ) {
        $cookie[] = "{$key}={$value}";
    };
    $cookie = implode('; ', $cookie);

curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// SOCKS5
$data = curl_exec($ch);

curl_close($ch);
return $data;

}




function rlink($link)
{

    $host = HOST;
    preg_match('/[a-z0-9]*\.([a-z0-9]+)?/i',$link,$match);
    $end = @$match[1];

    if(!in_array($end, array('png','js','css','cfm')))
    {
        if(preg_match('/^http/',$link))
        {

            if(strpos('https://www.sunfrogshirts.com/',$link) == 0)
            {

                $link = explode('https://www.sunfrogshirts.com/',$link);
                $link= @$link[1];
                $linkx =  'href="'.$host.ltrim($link,'/').'"';


            }
            else{
                $linkx = 'href="'.$link.'"';

            }
        }
        else{
            $linkx =  'href="'.$host.ltrim($link,'/').'"';

        }
    }
    else{
        if($end=='cfm')
        {
            $link.='?'.AFF;

        }
        if(preg_match('/^sellers/',$match[0]))
        {
            $link=$host.ltrim($link,'/');

        }
        $linkx = 'href="'.$link.'"';
    }
    return $linkx;


}
$link  = 'https://www.sunfrogshirts.com/'.$link;
$base  =  '<base href="https://www.sunfrogshirts.com/"/>';
$html =  get_link($link);
$html = str_replace('<link rel="image_src" href="','<link rel="image_src" hrefx="',$html);
$html = str_replace('<meta property="og:url" content="https://www.sunfrogshirts.com/','<meta property="og:url" content="http://www.sunfrogcheap.com/',$html);
$html = preg_replace('/href="([^"]+)"/eis',"rlink('$1')",$html);
$html = str_replace('<head>','<head>'.$base,$html);
//$html = preg_replace('/<input type="submit" name="submit" value="Add To Cart"[^>]+>/','<a href="http://www.sunfrogshirts.com/'.$rlink.'?'.AFF.'" target="_blank" rel="nofollow"><img src="'.HOST.'card.png"></a>',$html);
$html = str_replace('/search/index.cfm',HOST.'search.php?'.AFF,$html);
$html = preg_replace('/<img[^>]+class="logo"[^>]*>/','<img class="logo" src="'.HOST.LOGO.'">',$html);

if(!$_SESSION['aff'])
{
$iframe ='<iframe src="https://www.sunfrogshirts.com/terms/?'.AFF.'" style="display: none"></iframe>';
$_SESSION['aff'] = 1;
}

$html = str_replace('</body>',$iframe.'</body>'.$base,$html);
$html = str_replace('<link rel="image_src" hrefx="','<link rel="image_src" href="',$html);
date_default_timezone_set("Asia/Saigon"); 
$time= date('d-m-Y H:i:s');
$myfile = fopen("logip.txt", "a+");
fwrite($myfile, $_SERVER['REMOTE_ADDR']."|".$time."\n");
fclose($myfile);
echo $html;